package com.ruicar.afs.cloud.channel.common.mq.sender.impl;

import com.ruicar.afs.cloud.channel.affiliation.entity.ChannelAffiliatedUnitsTemp;
import com.ruicar.afs.cloud.channel.affiliation.service.ChannelAffiliatedUnitsTempService;
import com.ruicar.afs.cloud.common.modules.dto.mq.affiliation.AffiliationDto;
import com.ruicar.afs.cloud.common.modules.dto.mq.affiliation.AffiliationStatusInfo;
import com.ruicar.afs.cloud.common.mq.rabbit.message.AfsTransEntity;
import com.ruicar.afs.cloud.common.mq.rabbit.message.MqTransCode;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * 提交挂靠实现类
 *
 * @author panhj
 */
@Service
@AllArgsConstructor
public class CaseAffiliationStatusSenderImpl {
    /***
     * 挂靠单位service
     */
    private final ChannelAffiliatedUnitsTempService channelAffiliatedUnitsTempService;


    /**
     * 返回
     *
     * @param id
     * @return
     */
    public AfsTransEntity<AffiliationStatusInfo> returnAffiliationStatusInfo(String id) {
        AfsTransEntity<AffiliationStatusInfo> transEntity = new AfsTransEntity<>();
        AffiliationStatusInfo affiliationStatusInfo = new AffiliationStatusInfo();
        ArrayList<AffiliationDto> affiliationDtoArrayList = this.affiliationDtoArrayList(id);
        affiliationStatusInfo.setAffiliationDtoArrayList(affiliationDtoArrayList);
        transEntity.setTransCode(MqTransCode.AFS_CHANNEL_CHANNEL_CASE_CTM_UPDATE_STATUS);
        transEntity.setData(affiliationStatusInfo);
        return transEntity;
    }

    /**
     * 修改的挂靠list
     */
    public ArrayList<AffiliationDto> affiliationDtoArrayList(String id) {
        ArrayList<AffiliationDto> affiliationDtoArrayList = new ArrayList<>();
        String[] idArray = id.split(",");
        for (int j = 0; j < idArray.length; j++) {
            Long ids = Long.valueOf(idArray[j]);
            ChannelAffiliatedUnitsTemp channel = channelAffiliatedUnitsTempService.getById(ids);
            AffiliationDto affiliationDto = new AffiliationDto();
            affiliationDto.setAffiliatedName(channel.getAffiliatedName());
            affiliationDto.setApplyTime(channel.getApplyTime());
            affiliationDto.setBusiType(channel.getBusiType());
            affiliationDto.setCarCardComplete(channel.getCarCardComplete());
            affiliationDto.setCooperPlat(channel.getCooperPlat());
            affiliationDto.setCreateBy(channel.getCreateBy());
            affiliationDto.setCreateTime(channel.getCreateTime());
            affiliationDto.setInLibraryOrNot(channel.getInLibraryOrNot());
            affiliationDto.setLegalPersonIdcard(channel.getLegalPersonIdcard());
            affiliationDto.setLegalPersonName(channel.getLegalPersonName());
            affiliationDto.setLegalPersonTel(channel.getLegalPersonTel());
            affiliationDto.setStatus(channel.getStatus());
            affiliationDto.setOperateStatus(channel.getOperateStatus());
            affiliationDto.setOperCity(channel.getOperCity());
            affiliationDto.setRegisteredAddress(channel.getRegisteredAddress());
            affiliationDto.setRegisteredCity(channel.getRegisteredCity());
            affiliationDto.setRegisteredProvince(channel.getRegisteredProvince());
            affiliationDto.setRegisteredCapital(channel.getRegisteredCapital());
            affiliationDto.setRegisteredTime(channel.getRegisteredTime());
            affiliationDto.setSocUniCrtCode(channel.getSocUniCrtCode());
            affiliationDto.setWhetherLicence(channel.getWhetherLicence());
            affiliationDto.setDelFlag(channel.getDelFlag());
            affiliationDto.setMonthlyApplicationNum(channel.getMonthlyApplicationNum());
            affiliationDto.setMonthlySurplusNum(channel.getMonthlySurplusNum());
            affiliationDto.setTotalApplicationNum(channel.getTotalApplicationNum());
            affiliationDto.setTotalSurplusNum(channel.getTotalSurplusNum());
            affiliationDto.setLongTermOrNot(channel.getLongTermOrNot());
            affiliationDto.setId(channel.getId());
            affiliationDto.setUpdateTime(channel.getUpdateTime());
            affiliationDto.setUpdateBy(channel.getUpdateBy());
            affiliationDto.setLimitValue(channel.getLimitValue());
            affiliationDto.setWarningValue(channel.getWarningValue());
            affiliationDto.setFoundedTime(channel.getFoundedTime());
            affiliationDto.setTermValidity(channel.getTermValidity());
            affiliationDto.setOprTermValidity(channel.getOprTermValidity());
            affiliationDto.setTransPermitValidity(channel.getTransPermitValidity());
            affiliationDto.setPeopleCardComplete(channel.getPeopleCardComplete());
            affiliationDto.setPeoCarCardProportion(channel.getPeoCarCardProportion());
            affiliationDto.setPeoCarCardComplete(channel.getPeoCarCardComplete());
            affiliationDto.setOperateVehicles(channel.getOperateVehicles());
            affiliationDto.setOperationYears(channel.getOperationYears());
            affiliationDtoArrayList.add(affiliationDto);
        }
        return affiliationDtoArrayList;
    }

}
